package com.dhcc.cdc.busi.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.entity.CdcStrucresultEntity;
import com.dhcc.cdc.busi.service.ICdcStrucresultService;
import com.dhcc.core.framework.annotion.BussinessLog;
import com.dhcc.core.framework.annotion.Permission;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 分析结果
 * 
 * @ClassName: CdcStrucresultController
 * @Description: TODO
 * @author jumper
 * @date 2021-03-15 10:20:06
 */
@Controller
@RequestMapping("${sys.backendPath}/cdc/cdcstrucresult")
public class CdcStrucresultController extends BaseController {

	private String PREFIX = "/backend/cdc/cdcstrucresult/";

	@Autowired
	private ICdcStrucresultService cdcStrucresultService;
	

    /**
     * 跳转到分析结果列表首页
     */
    @RequestMapping("")
    @Permission("cdcstrucresult:list")
    public String index() {
        return PREFIX + "cdcstrucresult.html";
    }
	
    /**
     * 跳转到新增分析结果
     */
    @RequestMapping("/to_add")
    @Permission("cdcstrucresult:add")
    public String toAdd() {
        return PREFIX + "cdcstrucresult_add.html";
    }
	
	/**
     * 跳转到修改分析结果
     */
    @RequestMapping("/to_update/{cdcStrucresultId}")
    @Permission("cdcstrucresult:update")
    public String toUpdate(@PathVariable Long cdcStrucresultId, Model model) {
        CdcStrucresultEntity cdcStrucresult = this.cdcStrucresultService.selectById(cdcStrucresultId);
        model.addAttribute("cdcStrucresult",cdcStrucresult);
        return PREFIX + "cdcstrucresult_edit.html";
    }

    /**
     * 获取分析结果列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    @Permission("cdcstrucresult:list")
    public Object list(@RequestParam Map<String, Object> params) {
		Page<CdcStrucresultEntity> page = new PageFactory<CdcStrucresultEntity>().defaultPage();
        List<CdcStrucresultEntity> result = this.cdcStrucresultService.page(page,params);
        page.setRecords((List<CdcStrucresultEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增分析结果
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Permission("cdcstrucresult:add")
    @BussinessLog(value = "新增分析结果")
    public Object add(CdcStrucresultEntity cdcStrucresult) {
        if (CommonUtil.isOneEmpty(cdcStrucresult)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        cdcStrucresult.insert();
        return R.ok();
    }

    /**
     * 删除分析结果
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @Permission("cdcstrucresult:delete")
    @BussinessLog(value = "删除分析结果")
    public Object delete(@RequestParam Long cdcStrucresultId) {
	
        this.cdcStrucresultService.deleteById(cdcStrucresultId);

        return R.ok();
    }

    /**
     * 修改分析结果
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @Permission("cdcstrucresult:update")
    @BussinessLog(value = "修改分析结果")
    public Object update(CdcStrucresultEntity cdcStrucresult) {
        if (CommonUtil.isOneEmpty(cdcStrucresult)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        CdcStrucresultEntity old = this.cdcStrucresultService.selectById(cdcStrucresult.getId());

        old.setSectionId(cdcStrucresult.getSectionId());
        old.setResultTypeId(cdcStrucresult.getResultTypeId());
        old.setResult(cdcStrucresult.getResult());
        old.setIsActive(cdcStrucresult.getIsActive());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
